Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Table of Contents generated with DocToc
An ES6 class
with some metaprogramming capabilities:
Implementation was inspired by / copy-pasted from Chapter 3 of The Little Book on CoffeeScript.
Have a look at the demo:
class X extends Multimix
gives you a class with the following static methods inherited through
Multimix
:
<class>.extend: ( object, settings = null ) ->
—extends class with the properties of object
(class-level mixin).
<class>.include: ( object, settings = null ) ->
—extends instances with the properties of object
(instance-level mixin).
<class>.get_keymethod_proxy = ( bind_target, f ) ->
—produces an instance method f
which will
translate calls from immediate attributes (as in, f.some_text some_value
) to calls to f
proper,
using the attribute name as first argument: f some_text, some_value
. I needed this for a specific
purpose and included the code as a demo how to implement such a thing.
export: ( target = null ) ->
—when called on an instance, returns an object with bound instance
methods; this allows to 'export' instance methods into a namespace without fearing 'JavaScript method
tear-off symptome':
my_instance = new My_class
{ method_a
method_b } = my_instance.export_methods()
# now you can use `method_a`, `method_b` without prefixing them with `my_instance`:
method_a 42
When argument target
is given, methods will be attached on that object (overwriting existing ones).
When extend()
or include()
are used with settings
as { overwrite: false, }
, an error will
be raised during class definition time when any name clashes are detected.
Code:
Multimix = require 'multimix'
#=========================================================================================================
# SAMPLE OBJECTS WITH INSTANCE METHODS, STATIC METHODS
#---------------------------------------------------------------------------------------------------------
object_with_class_properties =
find: ( id ) -> info "class method 'find()'", ( k for k of @ )
create: ( attrs ) -> info "class method 'create()'", ( k for k of @ )
#---------------------------------------------------------------------------------------------------------
object_with_instance_properties =
save: -> info "instance method 'save()'", ( k for k of @ )
#=========================================================================================================
# CLASS DECLARATION
#---------------------------------------------------------------------------------------------------------
isa = ( type, xP... ) ->
### NOTE realistic method should throw error when `type` not in `specs` ###
urge "µ1129 object #{rpr @instance_name} isa #{rpr type} called with #{rpr xP}"
urge "µ1129 my @specs: #{rpr @specs}"
urge "µ1129 spec for type #{rpr type}: #{rpr @specs[ type ]}"
#---------------------------------------------------------------------------------------------------------
class Intertype extends Multimix
@extend object_with_class_properties
@include object_with_instance_properties
#-------------------------------------------------------------------------------------------------------
constructor: ( @instance_name ) ->
super()
@specs = {}
@declare type, value for type, value of @constructor.base_types
@isa = Multimix.get_keymethod_proxy @, isa
#-------------------------------------------------------------------------------------------------------
declare: ( type, value ) ->
whisper 'µ7474', 'declare', type, rpr value
@specs[ type ] = value
#-------------------------------------------------------------------------------------------------------
@base_types =
foo: 'spec for type foo'
bar: 'spec for type bar'
##########################################################################################################
intertype_1 = new Intertype
intertype_2 = new Intertype
info 'µ002-1', Intertype.base_types
info 'µ002-2', intertype_1.declare 'new_on_it1', 'a new hope'
info 'µ002-3', 'intertype_1.specs', intertype_1.specs
info 'µ002-4', 'intertype_2.specs', intertype_2.specs
info 'µ002-5', intertype_1.isa 'new_on_it1', 1, 2, 3
info 'µ002-6', intertype_1.isa.new_on_it1 1, 2, 3
info 'µ002-7', intertype_2.isa 'new_on_it1', 1, 2, 3
info 'µ002-8', intertype_2.isa.new_on_it1 1, 2, 3
{ isa, declare, } = intertype_1.export_methods()
info 'µ002-9', isa 'new_on_it1', 1, 2, 3
info 'µ002-10', isa.new_on_it1 1, 2, 3
"JavaScript's prototypal inheritance is vastly simpler than class-based, 'classical' OOP". [citation needed]
get_my_prototype()
get_my_prototype()
(allows to access methods of protoype even from methods that were
defined in a mixin object)FAQs
Objects with auto-generated property chains
The npm package multimix receives a total of 0 weekly downloads. As such, multimix popularity was classified as not popular.
We found that multimix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.